package com.fire.controller;


import com.fire.exception.ServiceException;
import com.fire.response.ResultData;
import com.fire.service.ISmartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 智能导航表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-07
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequiredArgsConstructor
@Api(tags = {"智能导航模块"})
@RequestMapping("/smart")
public class SmartController {

    private final ISmartService smartService;

    /**
     * 分页查询智能导航数据
     * @return
     */
    @GetMapping("/query/like/{pageNo}/{pageSize}")
    @ApiOperation(value = "查询智能导航数据")
    public ResultData querySmartData(@PathVariable("pageNo") Integer pageNo,
                                       @PathVariable("pageSize") Integer pageSize,
                                       String location){
        Map<String,Object> map = smartService.querySmartData(pageNo,pageSize,location);
        return ResultData.success(map);
    }

    /**
     * 查询机器编号
     * @return
     */
    @GetMapping("/query/machine/{id}")
    @ApiOperation(value = "查询机器编号")
    public ResultData queryMachineId(@PathVariable("id") Integer id){
        List<String> list = smartService.queryMachineId(id);
        return ResultData.success(list);
    }

    /**
     * 发送位置经纬度给机器
     * @return
     */
    @GetMapping("/sent/{smartId}/{machineId}")
    @ApiOperation(value = "发送位置经纬度")
    public ResultData handlerSent(@PathVariable("smartId") Integer id,
                                  @PathVariable("machineId") String machineId) throws ServiceException {
        smartService.handlerSent(id,machineId);
        return ResultData.success();
    }
}
